package com.tanhua.server.controller;

import com.tanhua.model.vo.*;
import com.tanhua.server.service.SettingsService;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 首页交友管理控制层
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     *  今日佳人
     */
    @RequestMapping(value = "/todayBest",method = RequestMethod.GET)
    public ResponseEntity todayBest(){
        TodayBestVo todayBestVo = tanhuaService.todayBest();
        return ResponseEntity.ok(todayBestVo);
    }


    /**
     *  首页推荐用户分页列表
     */
    @RequestMapping(value = "/recommendation",method = RequestMethod.GET)
    public ResponseEntity findPageRecommendUser(RecommendUserVo recommendUserVo){
        PageResult<TodayBestVo> pageRecommendUser = tanhuaService.findPageRecommendUser(recommendUserVo);
        return ResponseEntity.ok(pageRecommendUser);
    }


    /**
     *  获取佳人信息
     */
    @RequestMapping(value = "/{id}/personalInfo",method = RequestMethod.GET)
    public ResponseEntity personalInfo(@PathVariable("id") Long personUserId){
        TodayBestVo todayBestVo = tanhuaService.personalInfo(personUserId);
        return ResponseEntity.ok(todayBestVo);
    }

    /**
     *  查看陌生人问题
     */
    @RequestMapping(value = "/strangerQuestions",method = RequestMethod.GET)
    public ResponseEntity strangerQuestions(Long userId){
        String content = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }


    /**
     *  回复陌生人问题
     */
    @RequestMapping(value = "/strangerQuestions",method = RequestMethod.POST)
    public ResponseEntity replyStrangerQuestions(@RequestBody Map<String,String> params){
        Long personUserId = Long.valueOf(params.get("userId"));//佳人用户id(接收消息用户id)
        String reply = params.get("reply");//回复内容
        tanhuaService.replyStrangerQuestions(personUserId,reply);
        return ResponseEntity.ok(null);
    }


    /**
     *  探花-左滑右滑 随机查询10个推荐用户
     *  1.recommendUser
     *  2.User_like
     *  3.tb_userInfo
     */
    @RequestMapping(value = "/cards",method = RequestMethod.GET)
    public ResponseEntity findCards(){
        List<TodayBestVo> todayBestVoList = tanhuaService.findCards();
        return ResponseEntity.ok(todayBestVoList);
    }


    /**
     *  探花-不喜欢  true:喜欢 false:不喜欢
     *  1.user_like
     *  2.redis
     */
    @RequestMapping(value = "/{id}/unlove",method = RequestMethod.GET)
    public ResponseEntity unlove(@PathVariable("id") Long recommendUserId){
        tanhuaService.love(recommendUserId,false);
        return ResponseEntity.ok(null);
    }


    /**
     *  探花-喜欢
     *  1.user_like
     *  2.friend
     *  3.redis
     *  4.环信
     */
    @RequestMapping(value = "/{id}/love",method = RequestMethod.GET)
    public ResponseEntity love(@PathVariable("id") Long recommendUserId){
        tanhuaService.love(recommendUserId,true);
        return ResponseEntity.ok(null);
    }

    /**
     *  搜附近
     *  1.userlocation
     *  2.tb_userInfo
     *  gender: 性别
     *  distance: 距离单位:米
     */
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseEntity searchNearUser(String gender, Long distance){
        List<NearUserVo> nearUserVoList = tanhuaService.searchNearUser(gender,distance);
        return ResponseEntity.ok(nearUserVoList);
    }

}
